

/*
* Copyright @ 2017 com.iflysse.trains
* crm 下午12:54:34
* All right reserved.
*
*/
	
package com.qf.service.serviceImpl;

import java.util.ArrayList;
import java.util.List;

import com.qf.dao.CrmClassDao;
import com.qf.dao.CrmStudentDao;
import com.qf.dto.CrmClassDto;
import com.qf.pojo.CrmClass;
import com.qf.pojo.PageClass;
import com.qf.service.CrmClassService;
import com.qf.utils.DateUtil;

/**
* @desc: crm
* @descripe:XXXX
* @author: 周锐
* @createTime: 2017年7月26日 下午12:54:34
* @history:
* @version: v1.0

*/

public class CrmClassServiceImpl implements CrmClassService {
    private CrmClassDao classdao;

    
	/*
	*(non-Javadoc)
	* @see com.qf.service.CrmClassService#addClass(com.qf.pojo.CrmClass)
	*/

	
	/**
	* @param classdao the classdao to set
	*/
	
	public void setClassdao(CrmClassDao classdao) {
	
		this.classdao = classdao;
	}
	

	
	/**
	* @param studentDao the studentDao to set
	*/
	


	@Override
	public void addClass(CrmClass crmclass) {

		classdao.addClass(crmclass);

	}

	/*
	*(non-Javadoc)
	* @see com.qf.service.CrmClassService#updateClass(com.qf.pojo.CrmClass)
	*/

	@Override
	public void updateClass(CrmClass crmclass) {

		classdao.updateClass(crmclass);

	}

	/*
	*(non-Javadoc)
	* @see com.qf.service.CrmClassService#findClassbyPage(int, int)
	*/

	@Override
	public PageClass findClassbyPage(int page, int size) {

		List<CrmClass> list = classdao.findClassbyPage(page, size);
		List<CrmClassDto> classdtos=new ArrayList<>();
		for(CrmClass crmclass:list){
			CrmClassDto classdto=new CrmClassDto();
			classdto.setClassId(crmclass.getClassId());
			classdto.setClassName(crmclass.getClassName());
			classdto.setCourseTypeId(crmclass.getCrmCourseType().getCourseTypeId());
			classdto.setCourseName(crmclass.getCrmCourseType().getCourseName());
			classdto.setCourseCost(crmclass.getCrmCourseType().getCourseCost());
			classdto.setTotal(crmclass.getCrmCourseType().getTotal());
			classdto.setBeginTime(DateUtil.tranfaceString(crmclass.getBeginTime()));
			classdto.setEndTime(DateUtil.tranfaceString(crmclass.getEndTime()));
			if(crmclass.getBeginTime()>System.currentTimeMillis()){
				classdto.setStatus("未开班");
			}else if(crmclass.getBeginTime()<=System.currentTimeMillis()&&crmclass.getEndTime()>=System.currentTimeMillis()){
				classdto.setStatus("已开班");
			}else if(crmclass.getEndTime()<System.currentTimeMillis()){
				classdto.setStatus("已结束");
			}
			classdto.setTotalCount(crmclass.getTotalCount());
			classdto.setUpgradeCount(crmclass.getUpgradeCount());
			classdto.setChangeCount(crmclass.getChangeCount());
			classdto.setRunoffCount(crmclass.getRunoffCount());
			classdto.setRemark(crmclass.getRemark());
			classdto.setUploadPath(crmclass.getUploadPath());
			classdto.setUploadFileName(crmclass.getUploadFileName());
			if(crmclass.getUploadTime()!=null){
			classdto.setUploadTime(DateUtil.tranfaceString(crmclass.getUploadTime()));
			}
			classdtos.add(classdto);
		}
		int count = classdao.findClasspage();
		int totalpage=(count-1)/size+1;
		return new PageClass(page,size,totalpage,classdtos);

	}

	
	/*
	*(non-Javadoc)
	* @see com.qf.service.CrmClassService#findClassbyId(java.lang.Long)
	*/
		
	@Override
	public CrmClass findClassbyId(Long classId) {
		
		//TODO
		return classdao.findclassbyId(classId);
			
	}

	
	/*
	*(non-Javadoc)
	* @see com.qf.service.CrmClassService#findClassByCourseId(java.lang.Long)
	*/
		
	@Override
	public List<CrmClassDto> findClassByCourseId(Long courseTypeId) {
		List<CrmClass> list = classdao.findClassByCourseId(courseTypeId);
		List<CrmClassDto> crmClasses=new ArrayList<>();
		for(CrmClass crmClass:list){
			CrmClassDto classdto=new CrmClassDto();
			classdto.setClassId(crmClass.getClassId());
			classdto.setClassName(crmClass.getClassName());
			crmClasses.add(classdto);
		}
		return crmClasses;
			
	}



	
	/*
	*(non-Javadoc)
	* @see com.qf.service.CrmClassService#findClassDtobyId(java.lang.Long)
	*/
		
	@Override
	public CrmClassDto findClassDtobyId(Long classId) {
		
		 CrmClass crmclass = classdao.findclassbyId(classId);
		 CrmClassDto classdto=new CrmClassDto();
		classdto.setClassId(crmclass.getClassId());
		classdto.setClassName(crmclass.getClassName());
		classdto.setCourseTypeId(crmclass.getCrmCourseType().getCourseTypeId());
		classdto.setCourseName(crmclass.getCrmCourseType().getCourseName());
		classdto.setCourseCost(crmclass.getCrmCourseType().getCourseCost());
		classdto.setTotal(crmclass.getCrmCourseType().getTotal());
		classdto.setBeginTime(DateUtil.tranfaceString(crmclass.getBeginTime()));
		classdto.setEndTime(DateUtil.tranfaceString(crmclass.getEndTime()));
		if(crmclass.getBeginTime()>System.currentTimeMillis()){
				classdto.setStatus("未开班");
		}else if(crmclass.getBeginTime()<=System.currentTimeMillis()&&crmclass.getEndTime()>=System.currentTimeMillis()){
				classdto.setStatus("已开班");
		}else if(crmclass.getEndTime()<System.currentTimeMillis()){
				classdto.setStatus("已结束");
		}
		classdto.setTotalCount(crmclass.getTotalCount());
		classdto.setUpgradeCount(crmclass.getUpgradeCount());
		classdto.setChangeCount(crmclass.getChangeCount());
		classdto.setRunoffCount(crmclass.getRunoffCount());
		classdto.setRemark(crmclass.getRemark());
		classdto.setUploadPath(crmclass.getUploadPath());
		classdto.setUploadFileName(crmclass.getUploadFileName());
		if(crmclass.getUploadTime()!=null){
		classdto.setUploadTime(DateUtil.tranfaceString(crmclass.getUploadTime()));
			}
		return classdto;
			
	}

}

	